﻿/***********************************************************************
 * Module:  CPFActivator.h
 * Author:  ZHANGHASI
 * Modified: 2020年12月7日 下午 3:50:14
 * Purpose: Declaration of the class CPFActivator
 ***********************************************************************/

#ifndef __CPFACTIVATOR_H__
#define __CPFACTIVATOR_H__

#include "CPF/CPFObject.h"


#define CPF_SET_INSTANCE(fun) \
    fun_inst = fun;
// 插件行动器单例对象
#define CPF_INSTANCE(type) \
    static CPFObject* instance() \
    { std::mutex locker; \
    locker.lock(); \
    static CPFObject* pObject = nullptr; \
    if (nullptr == pObject) \
    { pObject = new type(); } \
    locker.unlock(); \
    return pObject;}

// 插件行动器对象
#define CPF_OBJECT_ADDRESS(type) \
    CPF_OBJECT_API CPFObject* cpf_create_instance() \
    { return type::instance(); } 

/**
 * \class   CPF_EXPORT
 *
 * \brief   插件启动器.
 *
 * \author  zhanghs
 * \date    2020/12/8
 */
class CPF_EXPORT CPFActivator : public CPFObject
{
public:

    /**
     * \fn  CPFActivator::CPFActivator();
     *
     * \brief   构造函数.
     *
     * \author  zhanghs
     * \date    2020/12/8
     */
    CPFActivator();

    /**
     * \fn  virtual CPFActivator::~CPFActivator();
     *
     * \brief   析构函数.
     *
     * \author  zhanghs
     * \date    2020/12/8
     */
    virtual ~CPFActivator();

    /**
     * \fn  virtual bool CPFActivator::start(void);
     *
     * \brief   启动插件.
     *
     * \author  zhanghs
     * \date    2020/12/8
     *
     * \return  返回启动结果.
     */
    virtual bool start(void);

    /**
     * \fn  virtual bool CPFActivator::stop(void);
     *
     * \brief   停止插件.
     *
     * \author  zhanghs
     * \date    2020/12/8
     *
     * \return  返回停止结果.
     */
    virtual bool stop(void);

    /**
     * \fn  virtual std::string CPFActivator::name(void);
     *
     * \brief   插件名称.
     *
     * \author  zhanghs
     * \date    2020/12/8
     *
     * \return  返回插件名称.
     */
    virtual std::string name(void);

    /**
     * \fn  virtual std::string CPFActivator::version(void);
     *
     * \brief   插件版本.
     *
     * \author  zhanghs
     * \date    2020/12/8
     *
     * \return  返回插件版本.
     */
    virtual std::string version(void);

protected:
    // 对象创建函数
    CPF_PLUGIN_FUNCTION_INSTANCE fun_inst;

private:

};

#endif // __CPFACTIVATOR_H__
